﻿@model RentHouse.DTO.RoleEditDTO
@{
    ViewBag.Title = "Edit";
}


<div class="pd-20">

    <form class="form form-horizontal" id="form-admin-add">
        <div class="row cl">
            <label class="form-label col-3"><span class="c-red">*</span>角色名：</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" value="@Model.Name" placeholder="角色名" id="user-name" name="Name" datatype="*2-16" nullmsg="角色名不能为空">
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl">
            @foreach (var item in Model.PermissionsList)
            {
                <div class="col-4">
                    <input type="checkbox" id="permission_@item.Id" name="PermissionIds" value="@item.Id" checked="@item.IsUsed" />
                    <label for="permission_@item.Id">@item.Description</label>
                </div>
            }
            @Html.HiddenFor(Model => Model.Id)
        </div>
        <div class="row cl">
            <div class="col-9 col-offset-3">
                <input class="btn btn-primary radius" type="button" id="btn_Add" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</div>

@section footScript
{
    <script>
        $(function () {

            //对用户输入的信息进行校验
            //初始化验证插件
            var validform = $("#form-admin-add").Validform({ tiptype: 2 });

            $("#btn_Add").click(function () {

                var formObj = $("#form-admin-add").serializeArray();

                //当验证通过的时候发送ajax请求
                if (validform.check(false)) {

                    $.post("/Roles/Edit", formObj, function (data) {
                        if (data.State == 1) {
                            //弹出提示信息
                            layer.msg('添加成功', { icon: 1 });
                            //关闭遮罩层
                            //刷新列表
                            parent.location.reload();

                        }
                        else {
                            layer.msg(data.ErrorMessage, { icon: 5 });
                        }

                    }, "json");
                }

            });


        });
    </script>
}